<%-- 
    Document   : ShowAllPersons
    Created on : 2024年3月24日, 上午10:35:17
    Author     : JUST
--%>

<%@page import="java.util.List"%>
<%@page import="cn.edu.just.secondwebapp.entity.Person"%>
<%@page import="cn.edu.just.secondwebapp.daoimpl.PersonDaoImpl"%>
<%@page import="cn.edu.just.secondwebapp.util.DatabaseConnectionUtil"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%  
            
            request.setCharacterEncoding("utf-8");
            String fuzzyKey = request.getParameter("fuzzykey");
            if(fuzzyKey==null){
                fuzzyKey="";
            }
            DatabaseConnectionUtil dcu = new DatabaseConnectionUtil();
            PersonDaoImpl personDao = new PersonDaoImpl(dcu.getConnection());
            List<Person> persons  = personDao.findAll(fuzzyKey);
            dcu.close();
        %>
        <h1>人员信息管理系统</h1>
        <div style="display: flex;justify-content: flex-end"><span style="margin-right: 20px">${username}</span>
            |
            <span style="margin-left: 20px;margin-right: 30px"><a href="../servlet/LoginOut">退出</a></span>
        </div>
        
        
        <hr/>
        <form action="ShowAllPersons.jsp" method="post">
            <input type="text" name="fuzzykey" />
            <input type="submit" value="查询"/>
        </form>
        <a href="../jsp/person02/addperson.jsp">新增人员</a>
        <table border="1">
            <tr><th>ID</th><th>姓名</th><th>年龄</th><th>生日</th><th>工资</th><th colspan="2">操作</th></tr>
            <%
                for(Person p:persons){
            %>
            <tr>
                <td><%=p.getPid()%></td> 
                <td><%= p.getName()%></td>
                <td><%=p.getAge()%></td>
                <td><%=p.getBirthday()%></td>
                <td><%=p.getSalary()%></td>
                <td><a href="updateperson.jsp?pid=<%=p.getPid()%>&name=<%=p.getName()%>&age=<%=p.getAge()%>">修改</a></td>
                <td><a href="doremove.jsp?pid=<%=p.getPid()%>">删除</a></td>
            </tr>                
            <%    
                }
       
            %>
        </table>
    </body>
</html>
